#include <jni.h>
#include <string>
#include "iengine.h"
#include "engine_impl.h"

/**
 * JNI 接口
 */

#define JNIFUN(rettype, name)                                             \
  extern "C" rettype JNIEXPORT JNICALL Java_com_example_openglandroidrenderer_OpenGLEngine_##name

// OpenGL 引擎
IEngine *engine = nullptr;

JNIFUN(void, nativeCreateOpenGLEngine)(JNIEnv *env, jclass j_class) {
    if (nullptr == engine) {
        engine = EngineImpl::getInstance();
    }
}

JNIFUN(void, nativeInit)(JNIEnv *env, jclass j_class) {
    if (engine != nullptr) {
        engine->init();
    }
}

JNIFUN(void, nativeUninit)(JNIEnv *env, jclass j_class) {
    if (engine != nullptr) {
        engine->unInit();
    }
}

JNIFUN(void, nativeOpenCamera)(JNIEnv *env, jclass j_class) {
    if (engine != nullptr) {
        engine->openCamera();
    }
}

JNIFUN(void, nativeCloseCamera)(JNIEnv *env, jclass j_class) {
    if (engine != nullptr) {
        engine->closeCamera();
    }
}